//
//  SearchFriendViewController.m
//  LTChat
//
//  Created by apple on 4/21/14.
//  Copyright (c) 2014 fantasy. All rights reserved.
//

#import "SearchFriendViewController.h"
#import "AppDelegate.h"

@interface SearchFriendViewController ()

@end

@implementation SearchFriendViewController

-(void)dealloc
{
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.navigationItem.titleView = self.searchBar;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"查找" style:UIBarButtonItemStyleBordered target:self action:@selector(findUser:)];
//    [[self xmppStream] addDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)findUser:(UIBarButtonItem *)bar
{
    [[[self appDelegate] xmppChatManager] addFriendSubscribe:self.searchBar.text];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here, for example:
    // Create the next view controller.
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<#@"Nib name"#> bundle:nil];
    
    // Pass the selected object to the new view controller.
    
    // Push the view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
}
*/

-(AppDelegate *)appDelegate{
    
    return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}

-(XMPPStream *)xmppStream{
    
    return [[[self appDelegate] xmppChatManager] xmppStream];
}

-(BOOL)hidesBottomBarWhenPushed
{
    return YES;
}

-(void)groupAddUser
{
//    if ([jid rangeOfString:@"@"].location==NSNotFound){
//        jid=[NSString stringWithFormat:@"%@@%@",jid,[DRRRManager sharedManager].host];
//    }
//    XMPPMessage* message=[[XMPPMessage alloc]init];
//    [message addAttributeWithName:@"id" stringValue:@"chatroom-1"];
//    [message addAttributeWithName:@"to" stringValue:chatRoomJid];
//    NSXMLElement* element_x=[NSXMLElement elementWithName:@"x" xmlns:@"http://jabber.org/protocol/muc#user"];
//    [message addChild:element_x];
//    NSXMLElement* element_invite=[NSXMLElement elementWithName:@"invite"];
//    [element_invite addAttributeWithName:@"to" stringValue:jid];
//    [element_x addChild:element_invite];
//    if (reason){
//        NSXMLElement* element_reason=[NSXMLElement elementWithName:@"reason"];
//        element_reason.stringValue=reason;
//        [element_invite addChild:element_reason];
//    }
//    if (password){
//        NSXMLElement* element_password=[NSXMLElement elementWithName:@"password"];
//        element_password.stringValue=password;
//        [element_x addChild:element_password];
//    }
//    [[DRRRManager sharedManager].xmppStream sendElement:message];
}

@end
